//
//  UIView+customBackbutton.m
//  iOS_beboy
//
//  Created by wen on 2017/10/25.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "UIView+customBackbutton.h"
#import <objc/runtime.h>
#import "JRSwizzle.h"

@implementation UIView (customBackbutton)

+ (void)load{
    if (@available(iOS 11, *)) {
        [NSClassFromString(@"_UIBackButtonContainerView") jr_swizzleMethod:@selector(addSubview:) withMethod:@selector(iOS11BackButtonNoTextTrick_addSubview:) error:nil];
    }else{
        UIImage *backButtonImageDefault = [[UIImage imageNamed:@"back" ] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 15, 10, -20)];
        [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImageDefault forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
    }
}

- (void)iOS11BackButtonNoTextTrick_addSubview:(UIView *)view
{
    view.alpha = 0;
    if ([view isKindOfClass:[UIButton class]]) {
        UIButton *button = (id)view;
        [button setTitle:@" " forState:UIControlStateNormal];
    }
    [self iOS11BackButtonNoTextTrick_addSubview:view];
    
}

@end
